import React, { useState, useRef } from 'react';
import { connect } from 'react-redux';
import { View } from '@tarojs/components';
import { getCurrentInstance, useDidShow } from '@tarojs/taro';
import utils from '@/utils/index';
import GetPageComponents from '@/components/GetPageComponents';
import UnusualContain from '@/pages/mainPages/unusualContain/index';
import './index.scss';

const CustomerPage = ({}) => {
  const [pageName, setPageName] = useState(null);
  const [isPreview, setIsPreview] = useState(null);
  const urlParms = useRef({ display: false });

  useDidShow(() => {
    let unusualInfo = utils.getLocalStorage('unusualInfo');
    if (unusualInfo !== null) {
      utils.setLocalStorage('unusualInfo', null);
    }
    urlParms.current = getCurrentInstance().router.params;
    setIsPreview(!!urlParms.current?.pagePreview);
    setPageName(
      !!urlParms.current?.pagePreview ? urlParms.current?.pagePreview : urlParms.current?.pageName,
    );
  });

  let unusualInfo = utils.getLocalStorage('unusualInfo');

  return (
    <View className="standardCustomerPage">
      {unusualInfo ? (
        <UnusualContain unusualInfo={unusualInfo} />
      ) : (
        <>{pageName != null && <GetPageComponents isPreview={isPreview} pageName={pageName} />}</>
      )}
    </View>
  );
};

export default connect(({}) => ({}))(CustomerPage);
